import * as XLSX1 from "xlsx-js-style";
export async function printData(msg, data, header) {
  const wb = XLSX1.utils.book_new();
  let row = [];
  let row1 = [
    {
      v: msg.msg1,
      t: "s",
      s: {
        font: { sz: 16, color: { rgb: "000000" }, hpx: 40, bold: true },
        alignment: { horizontal: "center", vertical: "middle" },
      },
    },
  ];
  row.push(row1);
  row.push([]);
  let row4 = [];
  header.map((v) => {
    row4.push({
      v: v.label,
      t: "s",
      s: {
        font: { sz: 10, color: { rgb: "000000" }, bold: true },
        border: {
          top: { style: "thin" },
          bottom: { style: "thin" },
          left: { style: "thin" },
          right: { style: "thin" },
        },
      },
    });
  });
  row.push(row4);
  data.map((item) => {
    let row5 = [];
    header.map((item1) => {
      let itemvalue = "";
      if (item1.value == "create_time") {
        itemvalue = item.start_time + "-" + item.end_time;
      } else {
        itemvalue = item[item1.value] || "";
      }
      row5.push({
        v: itemvalue,
        t: "s",
        s: {
          font: { sz: 10, color: { rgb: "000000" } },
          border: {
            top: { style: "thin" },
            bottom: { style: "thin" },
            left: { style: "thin" },
            right: { style: "thin" },
          },
        },
      });
    });
    row.push(row5);
  });
  row.push([]);
  let row6 = [];
  let num1 = 0;
  let num2 = 0;
  let num3 = 0;
  data.map((item1) => {
    num1 = num1 + Number(item1.salary_payable || 0);
    num2 = num2 + Number(item1.paid_wages || 0);
    num3 = num3 + Number(item1.outstanding_wages || 0);
  });
  header.map((item) => {
    let content = "";
    if (item.value == "emp") {
      content = "总计";
    } else if (item.value == "salary_payable") {
      content = String(Number(num1).toFixed(4));
    } else if (item.value == "paid_wages") {
      content = String(Number(num2).toFixed(4));
    } else if (item.value == "outstanding_wages") {
      content = String(Number(num3).toFixed(4));
    } else {
      content = "";
    }
    row6.push({
      v: content,
      t: "s",
      s: {
        font: { sz: 12, color: { rgb: "000000" } },
      },
    });
  });
  row.push(row6);
  const ws = XLSX1.utils.aoa_to_sheet(row);
  ws["!merges"] = [
    { s: { r: 0, c: 0 }, e: { r: 0, c: header.length - 1 } },
    // { s: { r: 1, c: 0 }, e: { r: 1, c: 6 } },
    // { s: { r: 2, c: 0 }, e: { r: 2, c: 6 } },
  ];
  XLSX1.utils.book_append_sheet(wb, ws, "readme demo");
  XLSX1.writeFile(wb, `${msg.msg1}.xlsx`);
}
